/*
 * File Name：CWToast.java
 * Copyright：Copyright 2008 - 2012 CiWong.Inc. All Rights Reserved.
 * Description： CWToast.java
 * Modify By：jejun
 * Modify Date：2012-10-28
 * Modify Type：Add
 */
package com.ciwong.ciwongwrite.widget;
import android.content.Context;
import android.content.res.Resources;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ciwong.ciwongwrite.R;

/**
 * <p>
 * 习网吐司提示类
 * </p>
 * <p>
 * 继承{@link Toast}
 * </p>
 *
 * @author jejun
 * @version ciwong v.1.0 2012-10-28
 * @since ciwong v.1.0
 */
public class CWToast extends Toast
{
    /**
     * 提示错误信息图标
     */
    public static final int TOAST_TYPE_ERROR = 0;

    /**
     * 提示一般信息图标
     */
    public static final int TOAST_TYPE_ALERT = 1;

    /**
     * 正确执行某一项操作后提示的图标
     */
    public static final int TOAST_TYPE_SUC = 2;

    /**
     * 构造函数
     *
     * @param context
     *            上下文
     */
    public CWToast(Context context)
    {
        super(context);
    }


    /**
     *
     * Make a standard toast that just contains a text view.
     *
     * @param context
     *            The context to use. Usually your
     *            {@link android.app.Application} or
     *            {@link android.app.Activity} object.
     * @param text
     *            The text to show. Can be formatted text.
     * @param duration
     *            How long to display the message. Either {@link #LENGTH_SHORT}
     *            or {@link #LENGTH_SHORT}
     * @return CWToast
     */
    public static CWToast makeText(Context context, CharSequence text,
                                   int duration)
    {
        CWToast result = new CWToast(context);

        LayoutInflater inflate = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflate.inflate(R.layout.toast, null);
        TextView tv = (TextView) v.findViewById(R.id.message);
        tv.setText(text);
        result.setView(v);
        result.setDuration(duration);
        return result;
    }

    /**
     *
     * Make a standard toast that just contains a text view with the text from a
     * resource.
     *
     * @param context
     *            The context to use. Usually your
     *            {@link android.app.Application} or
     *            {@link android.app.Activity} object.
     * @param resId
     *            The resource id of the string resource to use. Can be
     *            formatted text.
     * @param duration
     *            How long to display the message. Either {@link #LENGTH_SHORT}
     *            or {@link #LENGTH_SHORT}
     *
     * @return CWToast
     * @throws Resources.NotFoundException
     *             if the resource can't be found.
     */
    public static CWToast makeText(Context context, int resId, int duration)
            throws Resources.NotFoundException
    {
        return makeText(context, context.getResources().getText(resId),
                duration);
    }

    /**
     * 提示错误信息
     *
     * @param mContext
     *            上下文
     * @param resId
     *            字符资源id
     * @return Toast
     */
    public static Toast error(Context mContext, int resId)
    {
        CWToast toast = makeText(mContext, resId, Toast.LENGTH_SHORT);
        return toast;
    }

    /**
     *
     * 提示错误信息
     *
     * @param mContext
     *            上下文
     * @param msg
     *            提示信息
     * @return Toast
     */
    public static Toast error(Context mContext, CharSequence msg)
    {
        CWToast toast = makeText(mContext, msg, Toast.LENGTH_SHORT);
        return toast;
    }

    /**
     * 一般提示
     *
     * @param mContext
     *            上下文
     * @param resId
     *            字符资源id
     * @return Toast
     */
    public static Toast alert(Context mContext, int resId)
    {
        CWToast toast = makeText(mContext, resId, Toast.LENGTH_SHORT);

        return toast;
    }

    /**
     * 一般提示
     *
     * @param mContext
     *            上下文
     * @param msg
     *            提示信息
     * @return Toast
     */
    public static Toast alert(Context mContext, CharSequence msg)
    {
        CWToast toast = makeText(mContext, msg, Toast.LENGTH_SHORT);

        return toast;
    }

    /**
     * 正确执行某项操作后的提示
     *
     * @param mContext
     *            上下文
     * @param resId
     *            字符资源id
     * @return Toast
     */
    public static Toast correct(Context mContext, int resId)
    {
        CWToast toast = makeText(mContext, resId, Toast.LENGTH_SHORT);

        return toast;
    }

    /**
     * 正确执行某项操作后的提示
     *
     * @param mContext
     *            上下文
     * @param msg
     *            提示信息
     * @return Toast
     */
    public static Toast correct(Context mContext, CharSequence msg)
    {
        CWToast toast = makeText(mContext, msg, Toast.LENGTH_SHORT);
        return toast;
    }

    @Override
    public void show()
    {
        setGravity(Gravity.CENTER, 0, 0);
        super.show();
    }
}
